def start():
    print('1.整式（含常数）')
    print('2.指数')
    print('3.对数')
    print('4.三角')
    print('5.反三角')
    print('6.分式')
    print('7.根式')
    print('0.其他')


def one():  # 整式
    from matplotlib import pyplot
    dict1 = {}
    x_list = []
    y_list = []
    a = int(input('请输入整式次数（若为常数则输0）:'))
    for i in range(a + 1):
        if i != a:
            dict1[a - i] = int(input('请输入' + str(a - i) + '次项系数:'))
        else:
            dict1[0] = int(input('请输入常数项:'))
    for i in range(-10, 10):
        for j in range(100):
            x = i + j * 0.01
            y = 0
            for k in range(a + 1):
                y += dict1[a - k] * (x ** (a - k))
            if y > 10:
                continue
            if y < -10:
                continue
            x_list.append(x)
            y_list.append(y)
    print('图像如图\n')
    pyplot.plot(x_list, y_list, color='blue')
    pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
    pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
    pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
    pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
    pyplot.show()


def two():  # 指数
    from matplotlib import pyplot
    import math
    a = input('请输入指数函数y=a^x中底数a的值（可输入e）：')
    if a == 'e':
        a = math.e
    else:
        a = float(a)
    x_list = []
    y_list = []
    for i in range(-10, 10):
        for j in range(100):
            x = i + j * 0.01
            y = a ** x
            if y > 10:
                continue
            if y < -10:
                continue
            x_list.append(x)
            y_list.append(y)
    print('图像如图\n')
    pyplot.plot(x_list, y_list, color='blue')
    pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
    pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
    pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
    pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
    pyplot.show()


def three():  # 对数
    from matplotlib import pyplot
    import math
    a = input('请输入对数函数中底数a的值（可输入e）：')
    if a == 'e':
        a = math.e
    else:
        a = float(a)
    x_list = []
    y_list = []
    for i in range(0, 10):
        for j in range(100):
            x = i + j * 0.01
            if x == 0:
                continue
            y = math.log(x, a)
            if y > 10:
                continue
            if y < -10:
                continue
            x_list.append(x)
            y_list.append(y)
    print('图像如图\n')
    pyplot.plot(x_list, y_list, color='blue')
    pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
    pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
    pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
    pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
    pyplot.show()


def four():
    from matplotlib import pyplot
    import math
    print('1.正弦（型）')
    print('2.余弦')
    print('3.正切')
    print('0.其他')
    kind_str = input('请输入函数种类:')
    # 1.正弦（型）
    if kind_str == '1':
        print('请输入函数y=A*sin(ωx+φ)+b的各参数值：')
        a = float(input('A：'))
        omega = float(input('ω：'))
        phi = input('φ；')
        if 'π' in phi:
            phi = float(phi[:-1]) * math.pi
        else:
            phi = float(phi)
        b = float(input('b；'))
        x_list = []
        y_list = []
        for i in range(-10, 10):
            for j in range(100):
                x = i + j * 0.01
                y = a * math.sin(omega * x + phi) + b
                if y > 10:
                    continue
                if y < -10:
                    continue
                x_list.append(x)
                y_list.append(y)
        print('图像如图\n')
        pyplot.plot(x_list, y_list, color='blue')
        pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
        pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
        pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
        pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
        pyplot.show()
    # 2.余弦
    elif kind_str == '2':
        x_list = []
        y_list = []
        for i in range(-10, 10):
            for j in range(100):
                x = i + j * 0.01
                y = math.cos(x)
                if y > 10:
                    continue
                if y < -10:
                    continue
                x_list.append(x)
                y_list.append(y)
        print('图像如图\n')
        pyplot.plot(x_list, y_list, color='blue')
        pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
        pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
        pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
        pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
        pyplot.show()
    # 3.正切
    elif kind_str == '3':
        x_list = []
        y_list = []
        x_l = []
        y_l = []
        for i in range(-10, 10):
            for j in range(100):
                x = i + j * 0.01
                y = math.tan(x)
                for k in range(-3, 4):
                    if x < math.pi / 2 + math.pi * k < x + 0.01:
                        x_list.append(x_l)
                        y_list.append(y_l)
                        x_l = []
                        y_l = []
                if y > 10:
                    continue
                if y < -10:
                    continue
                x_l.append(x)
                y_l.append(y)
        x_list.append(x_l)
        y_list.append(y_l)
        for i in range(len(x_list)):
            pyplot.plot(x_list[i], y_list[i], color='blue')
        pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
        pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
        pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
        pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
        pyplot.show()
    # 0.其他
    elif kind_str == '0':
        func = input('请输入函数解析式：')
        print('暂不支持，正在优化中')
        f = open('other functions', 'a')
        f.write(func + '\n')
        f.close()
    # 错误
    else:
        print('输错了，请重输')
        four()


def five():  # 反三角
    from matplotlib import pyplot
    import math
    print('1.反正弦')
    print('2.反余弦')
    print('3.反正切')
    print('0.其他')
    kind_str = input('请输入函数种类:')
    # 1.反正弦
    if kind_str == '1':
        x_list = []
        y_list = []
        for i in range(-1, 1):
            for j in range(100):
                x = i + j * 0.01
                y = math.asin(x)
                if y > 10:
                    continue
                if y < -10:
                    continue
                x_list.append(x)
                y_list.append(y)
        print('图像如图\n')
        pyplot.plot(x_list, y_list, color='blue')
        pyplot.plot([0, 0], [-5, 5], color='black')  # y轴
        pyplot.plot([-5, 5], [0, 0], color='black')  # x轴
        pyplot.plot([0], [5], color='black', marker='^')  # y轴箭头
        pyplot.plot([5], [0], color='black', marker='>')  # x轴箭头
        pyplot.show()
    # 2.反余弦
    elif kind_str == '2':
        x_list = []
        y_list = []
        for i in range(-1, 1):
            for j in range(100):
                x = i + j * 0.01
                y = math.acos(x)
                if y > 10:
                    continue
                if y < -10:
                    continue
                x_list.append(x)
                y_list.append(y)
        print('图像如图\n')
        pyplot.plot(x_list, y_list, color='blue')
        pyplot.plot([0, 0], [-5, 5], color='black')  # y轴
        pyplot.plot([-5, 5], [0, 0], color='black')  # x轴
        pyplot.plot([0], [5], color='black', marker='^')  # y轴箭头
        pyplot.plot([5], [0], color='black', marker='>')  # x轴箭头
        pyplot.show()
    # 3.反正切
    elif kind_str == '3':
        x_list = []
        y_list = []
        for i in range(-10, 10):
            for j in range(100):
                x = i + j * 0.01
                y = math.atan(x)
                if y > 10:
                    continue
                if y < -10:
                    continue
                x_list.append(x)
                y_list.append(y)
        print('图像如图\n')
        pyplot.plot(x_list, y_list, color='blue')
        pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
        pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
        pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
        pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
        pyplot.show()
    # 0.其他
    elif kind_str == '0':
        func = input('请输入函数解析式：')
        print('暂不支持，正在优化中')
        f = open('other functions', 'a')
        f.write(func + '\n')
        f.close()
    # 错误
    else:
        print('输错了，请重输')
        five()


def six():  # 分式
    from matplotlib import pyplot
    dict1 = {}
    dict2 = {}
    x_list = []
    y_list = []
    a = int(input('请输入分子次数（若为常数则输0）:'))
    for i in range(a + 1):
        if i != a:
            dict1[a - i] = int(input('请输入' + str(a - i) + '次项系数:'))
        else:
            dict1[0] = int(input('请输入常数项:'))
    b = int(input('请输入分母次数:'))
    for i in range(b + 1):
        if i != b:
            dict2[b - i] = int(input('请输入' + str(b - i) + '次项系数:'))
        else:
            dict2[0] = int(input('请输入常数项:'))
    x_l = []
    y_l = []
    for i in range(-10, 10):
        for j in range(100):
            x = i + j * 0.01
            y1 = 0
            y2 = 0
            for k in range(a + 1):
                y1 += dict1[a - k] * (x ** (a - k))
            for k in range(b + 1):
                y2 += dict2[b - k] * (x ** (b - k))
            if y2 == 0:
                x_list.append(x_l)
                y_list.append(y_l)
                x_l = []
                y_l = []
                continue
            else:
                y = y1 / y2
            if y > 10:
                continue
            if y < -10:
                continue
            x_l.append(x)
            y_l.append(y)
    x_list.append(x_l)
    y_list.append(y_l)
    print('图像如图\n')
    for i in range(len(x_list)):
        pyplot.plot(x_list[i], y_list[i], color='blue')
    pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
    pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
    pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
    pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
    pyplot.show()


def seven():  # 根式
    from matplotlib import pyplot
    dict1 = {}
    x_list = []
    y_list = []
    a = int(input('请输入根号下整式式次数:'))
    for i in range(a + 1):
        if i != a:
            dict1[a - i] = int(input('请输入' + str(a - i) + '次项系数:'))
        else:
            dict1[0] = int(input('请输入常数项:'))
    x_l = []
    y_l = []
    for i in range(-10, 10):
        for j in range(100):
            x = i + j * 0.01
            y1 = 0
            for k in range(a + 1):
                y1 += dict1[a - k] * (x ** (a - k))
            y = y1 ** 0.5
            if isinstance(y, complex):
                x_list.append(x_l)
                y_list.append(y_l)
                x_l = []
                y_l = []
                continue
            if y > 10:
                continue
            if y < -10:
                continue
            x_l.append(x)
            y_l.append(y)
    x_list.append(x_l)
    y_list.append(y_l)
    print('图像如图\n')
    for i in range(len(x_list)):
        pyplot.plot(x_list[i], y_list[i], color='blue')
    pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
    pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
    pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
    pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
    pyplot.show()
